package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args)throws Exception {
        System.out.println("请输入一个类名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        Class<?> c = Class.forName(name);
        Object o = c.newInstance();
        if(c.isAnnotationPresent(AutoRunClass.class)){
            Method [] methods = c.getMethods();
            for (Method m:methods){
                if(m.isAnnotationPresent(AutoRunMethod.class)){
                    m.invoke(o);
                }
            }
        }else {
            System.out.println("该类没有被AutoRunClass标注");
        }
    }
}
